<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属站点">
        <site-radio v-model="form.site_id" @change="search" />
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button :value="0">
            待审核
            <span v-if="props.badgeData[0] > 0" class="radio-group-tips">
              {{ props.badgeData[0] }}
            </span>
          </el-radio-button>
          <el-radio-button
            v-for="item in judgeList"
            :key="item.id"
            :value="item.sort"
          >
            {{ item.title }}
            <span
              v-if="props.badgeData[item.sort] > 0"
              class="radio-group-tips"
            >
              {{ props.badgeData[item.sort] }}
            </span>
          </el-radio-button>
          <el-radio-button :value="190">
            待打款
            <span v-if="props.badgeData[190] > 0" class="radio-group-tips">
              {{ props.badgeData[190] }}
            </span>
          </el-radio-button>
          <el-radio-button :value="200">已审核</el-radio-button>
          <el-radio-button :value="500">已拒绝</el-radio-button>
        </el-radio-group>
      </el-form-item>

      <br />
      <el-form-item label="归属月份">
        <el-date-picker
          v-model="form.belongs_date"
          class="filter-item"
          type="month"
          value-format="YYYY-MM"
          style="width: 200px"
          @change="search"
        />
      </el-form-item>
      <el-form-item label="企业名称">
        <el-input
          clearable
          style="width: 170px"
          v-model.trim="form.company_name"
          placeholder="请输入"
        />
      </el-form-item>

      <el-form-item label="分类">
        <el-input
          clearable
          style="width: 170px"
          v-model.trim="form.cate"
          placeholder="请输入"
        />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { useFormData } from '@/utils/use-form-data';
  import SiteRadio from '@/components/Site/radio.vue';
  import { ref } from 'vue';
  import { pageCompanyCostJudgeConfig } from '@/api/company';
  const emit = defineEmits(['search']);

  const props = defineProps({
    where: {
      type: Object
    },
    badgeData: Object
  });
  /** 表单数据 */
  const [form, resetFields] = useFormData({
    company: '',
    belongs_date: '',
    site_id: '',
    tenant_id: 0,
    status: props.where.status
  });

  /** 审核配置 */
  const judgeList = ref([]);
  const getJudgeConfig = () => {
    pageCompanyCostJudgeConfig({})
      .then((res) => {
        judgeList.value = res.list;
      })
      .catch((e) => {
        console.log(e);
      });
  };
  getJudgeConfig();

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };

  /**  重置 */
  const reset = () => {
    resetFields();
    search();
  };
</script>
